package org.mendoza.salud.hvt.listeners;


import org.mendoza.salud.hvt.model.AbstractEntity;

import javax.persistence.EntityListeners;
import javax.persistence.PrePersist;
import java.util.UUID;


/**
 * Created with IntelliJ IDEA.
 * User: Ricardo
 * Date: 06/11/13
 * Time: 10:32
 * To change this template use File | Settings | File Templates.
 */
@EntityListeners(value = {AbstractEntityListener.class})
public class AbstractEntityListener {
    @PrePersist
    public void onPrePersist(AbstractEntity abstractEntity) {
        if (abstractEntity.getUid() == null) {
            abstractEntity.setUid(UUID.randomUUID().toString());
        }
    }

}